package com.wuneng.ircontrol.myUtil.widget;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Display;
import android.view.Gravity;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ProgressBar;
import android.widget.TextView;


import com.wuneng.ircontrol.R;

/**
 * Created by 天地 on 2018/7/31.
 */

public class StorageProgressDialog extends Dialog {

    private Context context;

    private ProgressBar numberProgressBar;
    private TextView titleTv;
    private String title;

    public StorageProgressDialog(Context context, String title) {
        super(context, R.style.dialog_custom);
        this.context = context;
        this.title = title;

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Window window = getWindow();
        window.setGravity(Gravity.CENTER); // 此处可以设置dialog显示的位置为居中
        setContentView(R.layout.storage_dialog_layout);
        TextView tvTitle = (TextView) findViewById(R.id.tvTitle);
        tvTitle.setText(title);
        numberProgressBar = (ProgressBar) findViewById(R.id.storage_progress);
        numberProgressBar.setProgress(0);
        WindowManager windowManager = ((Activity) context).getWindowManager();
        Display display = windowManager.getDefaultDisplay();
        WindowManager.LayoutParams lp = getWindow().getAttributes();
        lp.width = display.getWidth() * 4 / 5;
        getWindow().setAttributes(lp);
        setCanceledOnTouchOutside(false);
        setCancelable(false);
    }

    public void showStorageDialog() {
        this.show();
    }

    public void hideStorageDialog() {
        this.dismiss();
    }

    public void setProgress(int process) {
        numberProgressBar.setProgress(process);
    }

    public void increaseProgress(int process) {
        numberProgressBar.incrementProgressBy(process);
    }

    public void setTitle(String title) {
        titleTv.setText(title.trim().toString());
    }
}
